﻿using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using KinectTouchDevice;

namespace Manipulations_1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : KinectMultipointWindow // Window
    {
        public MainWindow()
        {
            InitializeComponent();

        }

        private void _canvas_ManipulationStarting(object sender, ManipulationStartingEventArgs e)
        {
            e.ManipulationContainer = _canvas;
            e.Handled = true;

        }

        private void _canvas_ManipulationDelta(object sender, ManipulationDeltaEventArgs e)
        {
            var element = e.OriginalSource as UIElement;
            var transform = element.RenderTransform as MatrixTransform;
            var matrix = transform == null ? Matrix.Identity : transform.Matrix;

            matrix.ScaleAt(e.DeltaManipulation.Scale.X, e.DeltaManipulation.Scale.Y,
                           e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
            matrix.RotateAt(e.DeltaManipulation.Rotation, e.ManipulationOrigin.X, e.ManipulationOrigin.Y);
            matrix.Translate(e.DeltaManipulation.Translation.X, e.DeltaManipulation.Translation.Y);

            element.RenderTransform = new MatrixTransform(matrix);

            e.Handled = true;

        }
    }
}
